home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- #
- # USAGE : s.pl <tmppath>
-
- ($tmppath = $ARGV[0]) =~ s/(\&|'|")/\\\1/g; # escape &, ' and " chars with \
-
- $tmpfile = "$tmppath/AppBooster$$.plist";
-
- open TMPFILE, ">$tmpfile" or die "Couldn't write temporary file";
-
- %dico = ();
-
- $pscommand = "ps axwwo pid,ni,user,command";
- open SHELL2, "$pscommand |" or die "probleme";
-
- # PID NI COMMAND
- # 256 0 /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock -psn_0_393217
- # ...
-
- <SHELL2>; # On oublie ainsi la première ligne (PID NI COMMAND)
- while (<SHELL2>)
- {
- chop;
- @t = split(" ", $_, 4) ;
-
- $pid = $t[0] ;
- $command = $t[3];
-
- if( $pid != $$ && $command ne "ps axwwo pid ni user command") # On ne veut pas du process de ce script, ni de celui de ps dans la liste !
- {
- $_ = $t[2];
- if(/.+ -psn_(.+$)/)
- {
- $psn = $1;
- $psn =~ s/_/-/;
- } else {$psn = "?";}
-
- # en XML, les signes &, < et > doivent être codés.
-
- $t[2] =~ s/&/&/g;
- $t[2] =~ s/</</g;
- $t[2] =~ s/>/>/g;
-
- push @dico, {pid => $t[0], nice => $t[1], user => $t[2], command => $t[3], psn => $psn };
- }
- }
-
- close SHELL2;
-
- print TMPFILE '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">';
-
- print TMPFILE '<plist version="0.9">';
- print TMPFILE "\n<dict>\n";
-
- print TMPFILE "\t<key>psProcessesArray</key>\n";
- print TMPFILE "\t<array>\n";
- foreach (@dico)
- {
- print TMPFILE "\t\t<dict>\n";
- print TMPFILE "\t\t\t<key>pid</key><string>".$_->{pid}."</string>\n";
- print TMPFILE "\t\t\t<key>command</key><string>".$_->{command}."</string>\n";
- print TMPFILE "\t\t\t<key>psn</key><string>".$_->{psn}."</string>\n";
- print TMPFILE "\t\t\t<key>nice</key><string>".$_->{nice}."</string>\n";
- print TMPFILE "\t\t\t<key>user</key><string>".$_->{user}."</string>\n";
- print TMPFILE "\t\t</dict>\n";
- }
- print TMPFILE "\t</array>\n";
-
- #print TMPFILE "\t<key>user</key><string>".$user."</string>\n";
-
- print TMPFILE "</dict>\n";
- print TMPFILE '</plist>';
-
- close TMPFILE;
-
- # On indique à Cocoa le nom du fichier temporaire qui a été créé.
- # Si l'on commente la ligne suivante, le fichier temporaire ne sera pas effacé (debug)
- print $tmpfile;
-
-